
package com.kanjian.music.util;

import android.app.Activity;
import android.content.SharedPreferences;

import com.kanjian.music.KanjianApplication;

/**
 * SharedPreference工具类
 * @author xuyanjun@kanjian.com
 */
public class SharedPreferenceUtil {

    private static SharedPreferences preferences = KanjianApplication.getContext()
            .getSharedPreferences("settings", Activity.MODE_PRIVATE);

    private static SharedPreferences.Editor editor = preferences.edit();

    public static boolean put(String key, Object value) {
        if (value instanceof Integer) {
            editor.putInt(key, (Integer) value);
        } else if (value instanceof Boolean) {
            editor.putBoolean(key, (Boolean) value);
        } else if (value instanceof String) {
            editor.putString(key, (String) value);
        } else if (value instanceof Float) {
            editor.putFloat(key, (Float) value);
        } else if (value instanceof Long) {
            editor.putLong(key, (Long) value);
        }
        return editor.commit();
    }

    public static String getString(String key, String defValue) {
        return preferences.getString(key, defValue);
    }

    public static long getLong(String key, long defValue) {
        return preferences.getLong(key, defValue);
    }
    
    public static int getInt(String key, int defValue) {
        return preferences.getInt(key, defValue);
    }
    
    public static float getFloat(String key, float defValue) {
        return preferences.getFloat(key, defValue);
    }
    
    public static boolean getBoolean(String key, boolean defValue) {
        return preferences.getBoolean(key, defValue);
    }
    

}
